<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <link rel="stylesheet" href="/manageSystem/layui/css/layui.css">
<!--    <link rel="stylesheet" href="layui-v2.6.8/layui/css/layui.css">-->
    <link rel="stylesheet" href="/manageSystem/css/common.css">


    <link rel="stylesheet" href="/manageSystem/layui/extend/dtree.css">
    <link rel="stylesheet" href="/manageSystem/layui/extend/font/dtreefont.css">
    <link rel="stylesheet" href="/manageSystem/layui/extend/formSelects-v4.css">
    <style>
        .layui-form{
            /*margin-right: 20px;*/
            margin: 40px 40px 40px 10px;
        }
        .layui-form-label{
            width: 90px;
            padding-left: 0;
            padding-right: 0;
        }
    </style>
</head>

<body>
    <form class="layui-form" action="">
        <input type="hidden" name="_method" value="PUT">
        <!--学号-->
        <div class="layui-form-item">
            <label for="studentId" class="layui-form-label">学号</label>
            <div class="layui-input-block">
                <input type="text" id="studentId" name="studentId" required  lay-verify="required" placeholder="学号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--姓名-->
        <div class="layui-form-item">
            <label for="studentName" class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" id="studentName" name="studentName" required  lay-verify="required" placeholder="姓名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--身份证-->
        <div class="layui-form-item">
            <label for="idCard" class="layui-form-label">身份证</label>
            <div class="layui-input-block">
                <input type="text" id="idCard" name="idCard" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--性别-->
        <div class="layui-form-item">
            <label class="layui-form-label" id="gender">性别</label>
            <div class="layui-input-block">
                <input type="radio" id="man" name="gender" value="1" title="男">
                <input type="radio" id="woman" name="gender" value="0" title="女" checked>
            </div>
        </div>
        <!--入学类型-->
        <div class="layui-form-item">
            <label class="layui-form-label">入学类型</label>
            <div class="layui-input-block">
                <select id="admissionType-select" name="admissionType" lay-verify="required">
                    <option value=""></option>
                    <option value="0">高考</option>
                    <option value="1">学考</option>
                    <option value="2">3+2</option>
                    <option value="3">成考</option>
                </select>
            </div>
        </div>
        <!--入学时间-->
        <div class="layui-form-item">
            <label class="layui-form-label">入学时间</label>
            <div>
                <div class="layui-input-block">
                    <input type="date" class="layui-input" id="admissionDate" name="admissionDate" placeholder="请选择">
                </div>
            </div>
        </div>
        <!--就读类型-->
        <div class="layui-form-item">
            <label class="layui-form-label">就读类型</label>
            <div class="layui-input-block">
                <select id="studyType-select" name="studyType" lay-verify="required">
                    <option value=""></option>
                    <option value="0">全日制</option>
                    <option value="1">非全日制</option>
                </select>
            </div>
        </div>
        <!--最高学历-->
        <div class="layui-form-item">
            <label class="layui-form-label">最高学历</label>
            <div class="layui-input-block">
                <select id="educationDegree-select" name="educationDegree" lay-verify="required">
                    <option value=""></option>
                    <option value="0">专科</option>
                    <option value="1">本科</option>
                    <option value="2">研究生</option>
                    <option value="3">硕士</option>
                    <option value="4">博士</option>
                </select>
            </div>
        </div>
        <!--就读年限-->
        <div class="layui-form-item">
            <label class="layui-form-label">就读年限</label>
            <div class="layui-input-block">
                <select id="studyYear-select" name="studyYear" lay-verify="required">
                    <option value=""></option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                </select>
            </div>
        </div>
        <!--政治面貌-->
        <div class="layui-form-item">
            <label class="layui-form-label">政治面貌</label>
            <div class="layui-input-block">
                <select id="politicalStatus-select" name="politicalStatus" lay-verify="required">
                    <option value=""></option>
                    <option value="0">群众</option>
                    <option value="1">党员</option>
                </select>
            </div>
        </div>
        <!--家庭地址-->
        <div class="layui-form-item">
            <label class="layui-form-label">家庭地址</label>
            <div class="layui-input-block">
                <input type="text" id="address" name="address" required  lay-verify="required" placeholder="家庭地址" autocomplete="off" class="layui-input">
            </div>
        </div>
        <!--按钮-->
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
<!--                <button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
            </div>
        </div>
    </form>

    <script src="/js/jquery.js"></script>
    <script src="/manageSystem/layui/layui.js"></script>

    <script src="/js/myWebConfig.js"></script>
    <script>
        let studentInfoData = {}
        console.log("==================== 修改学生页面： ====================")
        // 获取学生信息对象。
        let jsonData = JSON.parse(window.sessionStorage.getItem("studentInfo"))
        console.log("学号：" + jsonData.studentId)
        // 获取学生信息。
        $.get(webUrl+studentsDataPrefix+"/studentInfo/"+jsonData.studentId,function (data) {
            // console.log("回传的数据：")
            // console.log(data)
            studentInfoData = JSON.parse(data)
            // console.log(studentInfoData)
            // console.log(typeof JSON.parse(data))
            // console.log(JSON.parse(data))
        })
        console.log("学生信息：")
        console.log(studentInfoData)

        $.ajaxSettings.async = true;   //恢复异步执行
    </script>
    <!--页面加载完成之后，进行数据请求-->
    <script>
        // 获取请求头信息。
        window.onload = function () {
            $("#studentId").val(studentInfoData.data.studentId)     // 学号
            $("#studentName").val(studentInfoData.data.studentName) // 姓名
            $("#idCard").val(studentInfoData.data.idCard)           // 身份证

            console.log("性别：" + studentInfoData.data.gender)      // 性别
            let gender = studentInfoData.data.gender
            if (gender === 1){
                $("#man").attr("checked",true);
                $("#woman").attr("checked",false);
                // console.log("男：" + $("#man").val())
            }else if (gender === 0){
                $("#woman").attr("checked",true);
                $("#man").attr("checked",false);
                // console.log("女：" + $("#woman").val())
            }
            // $("#gender+div").val(studentInfoData.data.gender)

            $("#admissionType-select").val(studentInfoData.data.admissionType)          // 入学类型
            // $("#admissionDate").val("2021-09-08")
            // var d = new Date(studentInfoData.data.admissionDate)
            // console.log("当前时间：" + d)
            // console.log("当前时间：" + d.toISOString())
            // console.log("当前时间：" + d.toLocaleDateString())
            // console.log("当前时间：" + d.toUTCString())
            // console.log("当前时间：" + d.toDateString())
            $("#admissionDate").val(studentInfoData.data.admissionDate)                 // 入学时间
            $("#studyType-select").val(studentInfoData.data.studyType)                  // 就读类型
            $("#educationDegree-select").val(studentInfoData.data.educationDegree)      // 最高学历
            $("#studyYear-select").val(studentInfoData.data.studyYear)                  // 就读年限
            $("#politicalStatus-select").val(studentInfoData.data.politicalStatus)      // 政治面貌
            $("#address").val(studentInfoData.data.address)
            // 读取
            // key
            // let loginDataStoreKey = 'App.loginDataStoreKey';
            // let loginDataStoreKey = 'userInfo';
            // 获取 key
            // let tempData = window.sessionStorage.getItem(loginDataStoreKey);
            // let tempData = window.sessionStorage.getItem("studentInfo");
            // console.log("==================== 修改学生页面： ====================")
            // console.log("类型：" + typeof tempData)
            // let jsonData = JSON.parse(tempData)
            // console.log( jsonData)
            // console.log(typeof jsonData)
        }
    </script>
    <script>
        //Demo
        layui.use('form', function(){
            var form = layui.form;

            //监听提交
            form.on('submit(formDemo)', function(data){
                console.log("数据提交")
                console.log(data)
                console.log(JSON.stringify(data.field))
                let studentInfoData = JSON.stringify(data.field)
                data.field._method = "PUT"
                console.log(data)
                console.log(JSON.stringify(data.field))

                $.ajax({
                    url: webUrl + studentsDataPrefix + "/studentInfo/" + data.field.studentId,
                    type: 'PUT',
                    contentType: "application/json",//设置请求参数类型为json字符串
                    dataType: "json",
                    // data: { _method: "PUT",studentName: data.field.studentName},
                    data: JSON.stringify(data.field),
                    success: function( response ) {
                        console.log("回传的数据")
                        console.log(response)
                        if (response.msg === "成功"){
                            parent.layer.msg("修改成功", {icon: 6});
                            // 关闭当前打开的页面。
                            parent.layer.close(2); //再执行关闭
                        }else {
                            parent.layer.msg("修改失败", {icon: 5});
                        }
                    }
                });
                /*$.ajax({
                    url: webUrl + studentsDataPrefix + "/studentInfo/" + data.field.studentId,
                    type: "PUT",
                    contentType: "application/json",//设置请求参数类型为json字符串
                    data: {
                        _method: "PUT",
                        // 学生信息。
                        studentId: data.field.studentId,
                        // studentName: data.field.studentName,
                        studentName: "张三",
                        idCard: data.field.idCard,
                        gender: data.field.gender,
                        admissionType: data.field.admissionType,
                        admissionDate: data.field.admissionDate,
                        studyType: data.field.studyType,
                        educationDegree: data.field.educationDegree,
                        studyYear: data.field.studyYear,
                        politicalStatus: data.field.politicalStatus,
                        address: data.field.address,
                    },//将json对象转换成json字符串发送
                    dataType: "json",
                    success: function (result) {
                        console.log("回传的信息：")
                        console.log(result)
                        // layer.close(2);
                        if (result.msg === "成功"){
                            parent.layer.msg("修改成功", {icon: 6});
                            // 关闭当前打开的页面。
                            parent.layer.close(2); //再执行关闭
                        }else {
                            parent.layer.msg("修改失败", {icon: 5});
                        }
                    }
                });*/
                return false;
            });
        });
    </script>
    <!-- 入学日期 -->
    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#test'
                , format: 'yyyy-MM-dd'
            });
        });
    </script>
</body>

</html>